import { EventNames } from "../consts/EventNames";
import EventBus from "../core/EventBus";
/// <reference path="../core/behaviorTree/base/BaseNode.ts" />


export default class WaitAction extends bt.Action {
    private startTime: number;

    public static create(endTime: number): WaitAction {
        return new WaitAction(endTime);
    }

    constructor(private endTime: number) {
        super();
        this.startTime = 0;
    }

    execute(input: bt.BlackBoard): number {
        if (this.startTime == 0) {
            this.startTime = (new Date()).getTime();
        } else {
            let currTime = (new Date()).getTime();
            if (currTime - this.startTime > this.endTime) {
                this.startTime = 0;
                return bt.State.success;
            }
        }

        return bt.State.running;
    }
}